<?php include("methods.php");
include("sqlconnection.php");
session_start();
$username = "damien";//$_SESSION['username'];
 ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery Mobile Web App</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/stylesheet.css" rel="stylesheet" type="text/css"/>
<link href="css/jq-mobile-green-button-theme.css" rel="stylesheet" type="text/css"/>
<link href="css/jq-mobile-red-button-theme.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0rc2/jquery.mobile-1.0rc2.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0rc2/jquery.mobile-1.0rc2.min.js"></script>
<script src="js/phonegap.js" type="text/javascript"></script>
</head>
<body>
<div data-role="page" id="page"  data-theme="c">
    <div data-role="header" data-theme='a'>
    <a data-rel="back" data-role="button" data-icon="back">Back</a>
     <a href="logout.php" data-role="button" data-icon="delete" rel="external">Logout</a>
        <h1>Housemates</h1>
    </div>
    <div data-role="content">
        <ul data-role="listview" data-theme="c">
        <?php
			$db = new Database();
			$db->connect();
			
			$query = "select * from housemate";
			$housemateresult = mysql_query($query);
			$hashMap = array();
			while($rows1 = mysql_fetch_array($housemateresult)){
				$housemate_username = $rows1['username'];
				$id = $rows1['housemate_id'];
				$percentage = match($username, $housemate_username);
				
				
				
				$hashMap[$id] = $percentage;
			}
		
			
			arsort($hashMap);
			
			foreach($hashMap as $key => $value){
				$query = "select * from housemate where housemate_id = $key";
				$result = mysql_query($query);
				while($rows = mysql_fetch_array($result)){
					$desc = $rows['desc'];
					$state = $rows['state'];
					$suburb = $rows['suburb'];
					$city = $rows['city'];
					$rusername = $rows['username'];
					
					$queryusername = "select firstname, gender, dob, occupation, nationality, profile_pic from usertable where username = '$rusername'";
					$result = mysql_query($queryusername);
					$row = mysql_fetch_row($result);
					$rfirstname = $row[0];
					$rgender = $row[1];
					$rdob = $row[2];
					$roccupatation = $row[3];
					$rnationality = $row[4];
					$rprofilepic = $row[5];
					
					
				
					print "<li> <a href='user_profile.php?username=$rusername'>";
					print "<img src='$rprofilepic' style='margin-left:10px; margin-top:10px;'>";
					print "<div>";
					print "<h3>$rfirstname</h3>";
					//print "<p>$rgender	DOB:$rdob	$roccupatation";
					print "<img class='ul-li-icon' src='./images/$rnationality.png' width='30' height='30'></p>";
					print "<p style='white-space:normal'> $desc </p>";
					print "<div><span class='iconNum2'>Compatibility: <br />".$value."% </span><div name='cbar' class='cbar' style='width:".$value."px;'></div></div>" ;
					
					print "</div>";
					print "</a> </li>";
				}
			}
			$db->disconnect();
		
		?>
          
           
               
        </ul>

    </div>
</div>
</div>
</body>
</html>